package com.lovo.controller;

import com.google.gson.Gson;
import com.lovo.bean.GoodsOrder;
import com.lovo.service.IGoodsOrderService;
import com.lovo.service.serviceImpl.GoodsOrderImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "GoodsOrderServlet",urlPatterns = "/goodsOrder.do")
public class GoodsOrderServlet extends HttpServlet {

    IGoodsOrderService ig = new GoodsOrderImpl();

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        String method = request.getParameter("method");

        if (method == null || method.equalsIgnoreCase("getAll")){
            List<GoodsOrder> all = ig.getAll();
            response.getWriter().write(new Gson().toJson(all));
        }

    }
}
